package business.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import model.TError;
import model.TSite;
import business.basic.iHibBaseDAO;
import business.basic.iHibBaseDAOImpl;
import business.dao.SiteDAO;

@Component("sitedao")
public class SiteDAOImpl implements SiteDAO {

	private iHibBaseDAO bdao =null;
	
	public SiteDAOImpl() {
		bdao = new iHibBaseDAOImpl();
	}

	public void setBdao(iHibBaseDAO bdao) {
		this.bdao = bdao;
	}

	
	@Override
	public int add(TSite site) {
		Object obj = bdao.insert(site);
		if (obj!=null) {
			return Integer.parseInt(obj.toString());
		}
		return 0;
	}

	@Override
	public boolean update(TSite site) {
		return bdao.update(site);
	}

	@Override
	public boolean delete(int siteid) {
		return bdao.delete(TSite.class, siteid);
	}

	@Override
	public TSite getTSiteId(int siteid) {
		return (TSite)bdao.findById(TSite.class, siteid);
	}

	@Override
	public List<TSite> getTSite() {
		String hql = "from TSite";
		return bdao.select(hql);
	}

	@Override
	public List<TSite> getTSiteByWhere(String wherecondition, int startPage,
			int pageSize) {
		String hql = "from TSite";
		if (wherecondition !=null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		return bdao.selectByPage(hql, startPage, pageSize);
	}

	@Override
	public int getAmounTSiteByWhere(String wherecondition) {
		String hql = "select count(*) from TSite";
		if (wherecondition !=null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		return bdao.selectValue(hql);
	}

}
